
export function extractRecentSalesPerformance(doc: Document): string {
  try {
    // 1. 查找销售表现容器（对应Python的find('div', id='xxx')）
    const salesPerformanceContainer = doc.getElementById(
      "socialProofingAsinFaceout_feature_div"
    );
    if (!salesPerformanceContainer) {
      console.debug(
        "未找到销售表现容器 #socialProofingAsinFaceout_feature_div"
      );
      return "";
    }

    // 2. 查找销售数据文本元素（对应Python的find('span', id='xxx')）
    const salesTextElement = doc.getElementById(
      "social-proofing-faceout-title-tk_bought"
    );
    // 补充父容器内查找的兜底逻辑，避免元素存在但不在容器内的情况
    const fallbackSalesTextElement = salesPerformanceContainer.querySelector(
      "#social-proofing-faceout-title-tk_bought"
    );
    const targetSalesElement = salesTextElement || fallbackSalesTextElement;

    if (!targetSalesElement) {
      console.debug(
        "未找到销售表现文本元素 #social-proofing-faceout-title-tk_bought"
      );
      return "";
    }

    // 3. 提取并处理销售表现文本（对应Python的get_text(strip=True)）
    const salesText = targetSalesElement.textContent?.trim() || "";

    if (salesText) {
      return salesText;
    } else {
      console.error("提取到的销售表现文本为空");
      return "";
    }
  } catch (e) {
    console.error(
      `提取销售表现时发生错误: ${e instanceof Error ? e.message : String(e)}`
    );
    return "";
  }
}
